package com.lj.controller;

import com.github.pagehelper.PageInfo;
import com.lj.pojo.Directorlj;
import com.lj.pojo.Managerlj;
import com.lj.service.DirectorService;
import com.lj.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/director")
public class DirectorAction {
    public static final int PAGE_SIZE=5;
    @Autowired
    DirectorService directorService;
    @RequestMapping("/selectDirector")
    public String selectDirector(HttpServletRequest request){
        //得到第一页数据
        PageInfo info=directorService.selectDirector(1,PAGE_SIZE);
        request.setAttribute("info",info);
        return "admin/directorView";
    }
    //ajax分页翻页处理
    @ResponseBody
    @RequestMapping("/ajaxSplit")
    public void ajaxSplit(int page, HttpSession session){
        //取得当前page参数页面的数据
        PageInfo info=directorService.selectDirector(page,PAGE_SIZE);
        session.setAttribute("info",info);
    }
    @RequestMapping(value = "/insert")
    public String insert(Directorlj directorlj){
        int num=-1;
        num=directorService.insertDirector(directorlj);
        return "redirect:/director/selectDirector.action";
    }
    @RequestMapping("/delete")
    public String delete(String directorId){
        int nums=-1;
        nums=directorService.delete(directorId);
        return"forward:/director/selectDirector.action";
    }
    @ResponseBody
    @RequestMapping("/getDirectorById")
    public Directorlj getDirectorById(String directorId, HttpServletRequest request ){
        Directorlj directorlj=directorService.getById(directorId);
        return directorlj;
    }
    @RequestMapping("/update")
    public String update(Directorlj directorlj){
        int nums= directorService.update(directorlj);
        return "redirect:/director/selectDirector.action";
    }
}
